package com.ruoyi.framework.security.filter.ykz;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class CustomUserDetails implements UserDetails {
    private final SysUser sysUser;

    public CustomUserDetails(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 将 SysUser 的角色转换为 Spring Security 所需的 GrantedAuthority
        return null; // TODO: Implement role-to-authority conversion
    }

    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        // 是否过期 根据业务逻辑实现
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        // 基于 SysUser 的状态来判断
        return "0".equals(sysUser.getStatus());
    }

    public SysUser getSysUser() {
        return sysUser;
    }
}
